$.namespace('act.taskHistoricList');

act.taskHistoricList = function() {
	return {
		init : function() {
			this.initGrid();
			this.initComponents();
		},
		initComponents : function(){
			
		},
		initGrid : function() {
			$('#grid').datagrid({
				url : ctxRest + '/act/task/list-historic',
				contentType : 'application/json;charset=utf-8',
				fit : true,
				fitColumns : true,
				rownumbers : true,
				nowrap : true,
				striped : true,
				remoteSort : false,
				singleSelect : true,
				border : false,
				idField : 'id',
				columns : [ [ {
					title : '标题',
					field : 'vars',
					width : 120,
					formatter : function(value, row, index){
						return value.map.title;
					}
				}, {
					title : '当前环节',
					field : 'histTask',
					width : 80,
					formatter : function(value, row, index){
						return value.name;
					}
				}, {
					title : '流程名称',
					field : 'procDefName',
					width : 100
				}, {
					title : '流程版本',
					field : 'procDefVersion',
					width : 60
				}, {
					title : '流程图',
					field : 'diagramResourceName',
					width : 80
				}, {
					title : '完成时间',
					field : 'x',
					width : 80
				}, {
					title : '操作',
					field : 'option',
					width : 120,
					formatter : function(value, row, index) {//console.log(row);
						var opts = '';
						//<a href="${ctx}/act/task/form?taskId=${task.id}&taskName=${fns:urlEncode(task.name)}&taskDefKey=${task.taskDefinitionKey}&procInsId=${task.processInstanceId}&procDefId=${task.processDefinitionId}&status=${status}">详情</a>
						//opts += '<a href="javascript:void(0);" onclick="act.processList.remove(' + "'" + row.deployment.id + "'" + ')">[ 删除 ]</a>';
						opts += '<a href="javascript:void(0);" onclick="act.taskHistoricList.show(' + "'" + row.histTask.processDefinitionId + "'" + ')">[ 详情 ]</a>';
						return opts;
					}
				} ] ],
				toolbar : '#toolbar'
			});
		},
		show : function(procDefId) {
			if (procDefId) {
				$.ajax({
					type : 'POST',
					url : ctxRest + '/act/task/form',
					contentType : 'application/json;charset=utf-8',
					data : JSON.stringify({
						procDefId : procDefId
					}),
					success : function(result){
						console.log(result);
						if (result && result.url) {
							//window.location.href = (ctx + result.url);
						}
					}
				});
			}
		}
		
	};
}();

$(function() {
	act.taskHistoricList.init();
})